package org.example.spring_security_demo1.controller;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.security.Principal;

@RestController
@RequestMapping("/hello")
public class HelloController {


    @GetMapping("/hello")
    public String Hello(HttpSession session)
    {
        System.out.println(session.getId());
        return "Hello World";
    }

    @GetMapping("/getLogin")
    public Authentication getLogin(Authentication authentication) {

        return authentication;
    }

    @GetMapping("/getLogin2")
    public Principal getLogin2(){
        SecurityContext context = SecurityContextHolder.getContext();
        Authentication authentication = context.getAuthentication();
        return authentication;
    }
}
